package com.play.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.play.common.result.CommonResult;
import com.play.entity.Herb;
import com.play.service.IHerbService;
import com.play.vo.request.RequestVo;

@RestController
@RequestMapping("/herb")
public class HerbController {

	@Autowired
	private IHerbService herbService;
	
	@RequestMapping("/herbList")
	public CommonResult<PageInfo<Herb>> index(@RequestBody RequestVo req ){
		return CommonResult.success(herbService.selectHerbList(req.getPage(), req.getPageSize(), req.getName(), req.getDescription()));
	}
	
	@RequestMapping("/add")
	public CommonResult<String> add(@RequestBody Herb herb){
		int flag = herbService.addHerb(herb);
		if (flag > 0) {
			return CommonResult.success("添加成功。");
		}else {
			return CommonResult.success("添加失败。");
		}
	}
	
	@RequestMapping("/update")
	public CommonResult<String> update(@RequestBody Herb herb){
		int flag = herbService.updateHerb(herb);
		if (flag > 0) {
		return CommonResult.success("修改成功。");
		}else {
			return CommonResult.success("修改失败。");
		}
	}
	
}
